package com.starview.star.compiler.wff;

import com.starview.platform.data.type.Location;
import com.starview.star.compiler.ast.IAbstract;
import com.starview.star.compiler.util.PrettyPrintDisplay;
import com.starview.star.compiler.wff.WffOp.applyMode;

@SuppressWarnings("serial")
public class WfIfCnd implements WffCond
{
  private final WffCond test, thOp, elOp;

  public WfIfCnd(WffCond test, WffCond thOp, WffCond elOp)
  {
    this.test = test;
    this.thOp = thOp;
    this.elOp = elOp;
  }

  @Override
  public applyMode satisfied(IAbstract[] env, Location loc, WffEngine engine)
  {

    if (test.satisfied(env, loc, engine) == applyMode.validates)
      return thOp.satisfied(env, loc, engine);
    else
      return elOp.satisfied(env, loc, engine);
  }

  @Override
  public void prettyPrint(PrettyPrintDisplay disp)
  {
    disp.append("(");
    test.prettyPrint(disp);
    disp.append(":?");
    thOp.prettyPrint(disp);
    disp.append(":|");
    elOp.prettyPrint(disp);
    disp.append(")");
  }

}
